package com.shaw.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;


import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.shaw.client.MailService.Util;
import com.shaw.client.mvc.AppController;
import com.shaw.client.mvc.AppEvents;
import com.shaw.client.mvc.goal.ContactController;
import com.shaw.client.mvc.goal.GoalController;
import com.shaw.client.mvc.goal.MailController;
import com.shaw.client.mvc.goal.TaskController;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.state.CookieProvider;
import com.extjs.gxt.ui.client.state.StateManager;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class TestGxt implements EntryPoint {
	
	public static final String SERVICE = "MailService";
	
	public void onModuleLoad() {
		MailServiceAsync service=Util.getInstance();
	    ServiceDefTarget endpoint = (ServiceDefTarget) service;
	    String moduleRelativeURL =GWT.getModuleBaseURL()+ SERVICE;
	    endpoint.setServiceEntryPoint(moduleRelativeURL);
	    Registry.register(SERVICE, service);
	    // RootPanel.get().add(new MainLayout());
	    Dispatcher dispatcher = Dispatcher.get();
	    dispatcher.addController(new AppController());
	    dispatcher.addController(new GoalController());
	    dispatcher.addController(new MailController());
	    dispatcher.addController(new TaskController());
	    dispatcher.addController(new ContactController());
	    StateManager.get().setProvider(
			new CookieProvider(null, null, null, true));
	    Object object = StateManager.get().get("login");
	if (object == null || !(Boolean) object) {
		dispatcher.dispatch(AppEvents.LOGIN);
	} else {
		dispatcher.dispatch(AppEvents.INIT);
	}	
	
}
	}

		
	
	
	
	
	
	/* public static final String SERVICE = "mailservice";
		public void onModuleLoad() {
			MailServiceAsync service=Util.getInstance();
			    ServiceDefTarget endpoint = (ServiceDefTarget) service;
			    String moduleRelativeURL = SERVICE;
			    endpoint.setServiceEntryPoint(moduleRelativeURL);
			    Registry.register(SERVICE, service);
			// RootPanel.get().add(new MainLayout());
			Dispatcher dispatcher = Dispatcher.get();
			dispatcher.addController(new AppController());
			dispatcher.addController(new GoalController());
		    dispatcher.addController(new MailController());
		    dispatcher.addController(new TaskController());
		    dispatcher.addController(new ContactController());
			StateManager.get().setProvider(
					new CookieProvider(null, null, null, true));
			Object object = StateManager.get().get("login");
			if (object == null || !(Boolean) object) {
				dispatcher.dispatch(AppEvents.LOGIN);
			} else {
				dispatcher.dispatch(AppEvents.INIT);
			}	
			
		}*/
	
	
	
	

	
	
	
	
	
	
	
	
	
	

	/*private FormPanel formPanel;
	private TextField<String> textField_Name;
	private TextField<String> textField_Age;
	private com.extjs.gxt.ui.client.widget.button.Button btnAdd;
	private Button btnQuery;


	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get();
		
		this.formPanel = new FormPanel();
		this.formPanel.setHeading("用户信息");
		this.formPanel.setCollapsible(true);
		
		this.textField_Name = new TextField<String>();
		this.formPanel.add(this.textField_Name, new FormData("100%"));
		this.textField_Name.setFieldLabel("姓名");
		
		this.textField_Age = new TextField<String>();
		this.formPanel.add(this.textField_Age, new FormData("100%"));
		this.textField_Age.setFieldLabel("年龄");
		rootPanel.add(this.formPanel);
		rootPanel.setWidgetPosition(this.formPanel, 45, 51);
		this.formPanel.setSize("328px", "132px");
		
		this.btnAdd = new com.extjs.gxt.ui.client.widget.button.Button("新增用户");
		this.btnAdd.addSelectionListener(new SelectionListener<ButtonEvent>() {
			public void componentSelected(ButtonEvent ce) {
				UserEntity uEntity=new UserEntity();
				int age=Integer.parseInt(textField_Age.getValue());
				uEntity.setAge(age);
				uEntity.setUsername(textField_Name.getValue());
				UserServiceAsync uServiceAsync=Util.getInstance();
				uServiceAsync.isSaved(uEntity, new AsyncCallback<Boolean>() {

					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub
						
					}

					@Override
					public void onSuccess(Boolean result) {
						// TODO Auto-generated method stub
						if(true == result.booleanValue())
						{
							MessageBox.alert("提示", "保存成功", null);
							
						
						}
					}
				});
			}
		});
		
		
		rootPanel.add(this.btnAdd);
		this.btnAdd.setSize("83px", "34px");
		rootPanel.setWidgetPosition(this.btnAdd, 79, 203);
		
		this.btnQuery = new Button("查 询");
		this.btnQuery.addSelectionListener(new SelectionListener<ButtonEvent>() {
			public void componentSelected(ButtonEvent ce) {
				UserServiceAsync uServiceAsync=Util.getInstance();
				uServiceAsync.query(textField_Name.getValue(), new AsyncCallback<UserEntity>() {

					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub
						
					}

					@Override
					public void onSuccess(UserEntity result) {
						// TODO Auto-generated method stub
						textField_Age.setValue(Integer.toString(result.getAge()));
						
					}
				});
				
			}
		});
		

		rootPanel.add(this.btnQuery);
		this.btnQuery.setSize("83px", "34px");
		rootPanel.setWidgetPosition(this.btnQuery, 195, 203);
		
		
		
		

	
	
		
		
	}
}
*/